package cn.wolfcode.shop.service;

import cn.wolfcode.shop.domain.SkuPropertyValue;
import cn.wolfcode.shop.mapper.SkuPropertyValueMapper;
import com.alibaba.dubbo.config.annotation.Service;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@Service@Transactional
public class SkuPropertyValueServiceImpl implements ISkuPropertyValueService {
    @Autowired
    private SkuPropertyValueMapper skuPropertyValueMapper;

    @Override
    public List<SkuPropertyValue> selectByPId(Long skuPropertyId) {
        return skuPropertyValueMapper.selectByPId(skuPropertyId);
    }

    @Override
    public void saveOrUpdate(List<SkuPropertyValue> skuPropertyValues) {
        for (SkuPropertyValue skuPropertyValue : skuPropertyValues) {
            if (skuPropertyValue.getId() != null) {
                skuPropertyValueMapper.updateByPrimaryKey(skuPropertyValue);
            } else {
                skuPropertyValueMapper.insert(skuPropertyValue);
            }
        }
    }

    @Override
    public void delete(Long id) {
        skuPropertyValueMapper.deleteByPrimaryKey(id);
    }
}
